/*
 * Copyright (C) 2013 The original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.zapta.apps.maniana.model;

import com.zapta.apps.maniana.annotations.ApplicationScope;

/**
 * Represents the type of item repeats
 *
 * @author Elliott Mitchell
 */

@ApplicationScope
public enum ItemRepeatType {
	/** The type of repeats available */
	NONE(null,	(byte)0),
	DAY("day",	(byte)1),
	WEEK("week",	(byte)2),
	MONTH("month",	(byte)3),
	YEAR("year",	(byte)4);

	private final String mKey;

	private final byte mIndex;

	ItemRepeatType(String key, byte index) {
		mIndex=index;
		mKey=key;
	}

	/** Return value with given key */
    	public final static ItemRepeatType fromKey(String key) {
		int res;
		if(key==null) return NONE;
		if((res=key.compareTo("month"))==0) return MONTH;
		else if(res < 0) {
			if(key.compareTo("day")==0) return DAY;
		} else if((res=key.compareTo("week"))==0) return WEEK;
		else if(key.compareTo("year")==0) return YEAR;
		return NONE;
    	}

	public final String getKey() {
		return mKey;
	}

	public final byte getIndex() {
		return mIndex;
	}
}

